// Learn TypeScript:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/2.4/manual/en/scripting/life-cycle-callbacks.html

import BaseUI from "../framwork/BaseUI";
import qxc_tools from "../framwork/qxcTools/qxc_tools";
import GameData from "./data/GameData";

const {ccclass, property} = cc._decorator;

@ccclass
export default class begin extends BaseUI {
    baseUI_onLoad(): void {

    }
    baseUI_onDestroy(): void {

    }
    onBtn_click(target: cc.Button, onBtn_name: string): number | void {
        switch (onBtn_name) {
            case "btn_suiji":
                this.btn_suiji();
                break;
        }
    }
    init_data(d: any): void {

    }
    createInfo(){
        GameData.playerData.hp = qxc_tools.ranNumber(51,101);
        GameData.playerData.WL = qxc_tools.ranNumber(6,11);
        GameData.playerData.FS = qxc_tools.ranNumber(6,11);
        GameData.playerData.WF = qxc_tools.ranNumber(6,11);
        GameData.playerData.FF = qxc_tools.ranNumber(6,11);
        GameData.playerData.linggen1 = this.getLinggen();
        GameData.playerData.linggen2 = null;
        if(GameData.playerData.linggen1.num > 10){
            let ran = qxc_tools.ranNumber(0,100);
            if(ran<30){
                GameData.playerData.linggen2 = this.getLinggen();
            }
        }
    }
    getLinggen(){
        let linggen = ["金","木","水","火","土"];
        let levelStr = ["下品","中品","上品","极品"];
        let ranLinggen = qxc_tools.ranNumber(0,5);
        let linggenNum = qxc_tools.ranNumber(1,21);
        let level = 0;
        if(linggenNum < 6){
            level = 0;
        } else if(linggenNum < 11){
            level = 1;
        } else if(linggenNum < 16){
            level = 2;
        } else {
            level = 3;
        }
        let data = {
            name:linggen[ranLinggen],
            num:linggenNum,
            levelStr:levelStr[level],
            level:level,
        }
        return data;
    }
    setInfo(){
        this.SetLabel("str_linggen3","");
        this.GetGameObject("str_linggen2").active = false;
        this.SetLabel("str_xueliang",GameData.playerData.hp.toString());
        this.SetLabel("str_wuli",GameData.playerData.WL.toString());
        this.SetLabel("str_fashu",GameData.playerData.FS.toString());
        this.SetLabel("str_wufang",GameData.playerData.WF.toString());
        this.SetLabel("str_fafang",GameData.playerData.FF.toString());
        this.SetProgressBar("pro_xueliang",GameData.playerData.hp/100);
        this.SetProgressBar("pro_wuli",GameData.playerData.WL/10);
        this.SetProgressBar("pro_fashu",GameData.playerData.FS/10);
        this.SetProgressBar("pro_wufang",GameData.playerData.WF/10);
        this.SetProgressBar("pro_fafang",GameData.playerData.FF/10);
        this.SetLabel("str_linggen1",GameData.playerData.linggen1.name);
        this.SetLabel("str_level1",GameData.playerData.linggen1.levelStr + "(" + GameData.playerData.linggen1.num + ")");
        if(GameData.playerData.linggen2){
            this.GetGameObject("str_linggen2").active = true;
            this.SetLabel("str_linggen2",GameData.playerData.linggen2.name);
            this.SetLabel("str_level2",GameData.playerData.linggen2.levelStr + "(" + GameData.playerData.linggen2.num + ")");
            let sumStr = GameData.playerData.linggen1.name + GameData.playerData.linggen2.name;
            console.log(sumStr);
            switch(sumStr){
                case "火木":
                    this.SetLabel("str_linggen3","雷");
                    break;
                case "木水":
                    this.SetLabel("str_linggen3","生");
                    break;
                case "水金":
                    this.SetLabel("str_linggen3","冰");
                    break;
                case "金土":
                    this.SetLabel("str_linggen3","岩");
                    break;
                case "土火":
                    this.SetLabel("str_linggen3","风");
                    break;
            }
        }
        
    }
    btn_suiji(){
        this.createInfo();
        this.setInfo();
        console.log(GameData.playerData)
    }
}
